package csc309.datingapp;

import java.util.Date;
import java.util.Map;
import java.sql.*;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

import java.util.Vector;
import java.util.Enumeration;

import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;

public class SearchUser extends ActionSupport implements SessionAware {

	public String getCountry() {
		return country;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getEthnicity() {
		return ethnicity;
	}

	public void setEthnicity(String ethnicity) {
		this.ethnicity = ethnicity;
	}

	public String getReligion() {
		return religion;
	}

	public void setReligion(String religion) {
		this.religion = religion;
	}

	public int getDay() {
		return day;
	}

	public void setDay(int day) {
		this.day = day;
	}

	public int getMonth() {
		return month;
	}

	public void setMonth(int month) {
		this.month = month;
	}

	public int getYear() {
		return year;
	}

	public void setYear(int year) {
		this.year = year;
	}

	public int getFeet() {
		return feet;
	}

	public void setFeet(int feet) {
		this.feet = feet;
	}

	public int getInches() {
		return inches;
	}

	public void setInches(int inches) {
		this.inches = inches;
	}

	public String getGender() {
		return Gender;
	}

	public void setGender(String gender) {
		Gender = gender;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}
	
	private String country;
	private String city;
	private String ethnicity;
	private String religion;
	private int day;
	private int month;
	private int year;
	private int feet;
	private int inches;
	private String Gender;
	private String email;
	


	
	public Vector myArray = new Vector();

	public String execute() {

		Connection con;
		try {
			String dbUsername = "group09";
			String dbPassword = "asdasdqr3ggqq";

			Class.forName("com.mysql.jdbc.Driver");
			con = DriverManager.getConnection(
					"jdbc:mysql://bungle07.cs.toronto.edu", dbUsername,
					dbPassword);

			String query = "select * from group09.details";
//			String rest = "1 ";
//			
//			if (getCountry() != "") {
//				rest += " AND country REGEXP '" + getCountry() + "'";
//			}
//			if (getCity() != "") {
//				rest += " AND city REGEXP '" + getCity() + "'";
//			}
//			if (getReligion() != "") {
//				rest += " AND religion REGEXP '" + getReligion() + "'";
//			}
//			if (getGender() != "") {
//				rest += " AND gender REGEXP '" + getGender() + "'";
//			}
//			if (getEthnicity() != "") {
//				rest += " AND ethnicity REGEXP '" + getEthnicity() + "'";
//			}
//
//			if (getFeet() != 0) {
//				rest += " AND height REGEXP '" + getFeet();
//				if (getInches() != 0) {
//					rest += "ft" + getInches() + "'";
//				} else {
//					rest += "ft0'";
//				}
//			}
//
//			if (getYear() != 0 && getMonth() != 0 && getDay() != 0) {
//				rest += " AND dob REGEXP '" + getYear() + "-" + getMonth()
//						+ "-" + getDay() + "' ";
//			}
//
//			if (rest != "") {
//				query = query + " WHERE " + rest;
//			}

			Statement sql = con.createStatement();

			ResultSet results = sql.executeQuery(query);

			if (results != null) {
				while (results.next()) {
					myArray.add(new DEntries(getCity(),getEthnicity(),getReligion(),getDay(),getMonth(),getYear(),getFeet(), getInches(), getGender() , getEmail() ));  
				}
			}
			sql.close();
			con.close();
			return "success";
		} catch (Exception e) {
			return "exception";
		}
	}

	/* JavaBeans Properties to Receive Request Parameters */

	private Map session;

	public void setSession(Map session) {
		this.session = session;

	}
}
